package com.xw.comm.service.impl;

import com.xw.comm.service.LogService;
import jnr.ffi.Struct;
import org.springframework.stereotype.Service;

import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;

/**
 * @author xiongwei_vendor
 * @date 2021/9/16 14:42
 */
@Service
public class LogServiceImpl implements LogService {

    private Map<String, Boolean> logMap = new ConcurrentHashMap<>();

    @Override
    public Boolean isPrint(String key) {
        return logMap.getOrDefault(key, false);
    }

    @Override
    public Boolean isTruePrint(String key) {
        return logMap.getOrDefault(key, true);
    }

    @Override
    public void openLogPrint(String key) {
        modifyLogSwitch(key, true);
    }

    @Override
    public void closeLogPrint(String key) {
        modifyLogSwitch(key, false);
    }

    /**
     * 修改打印日志开关
     *
     * @param key
     * @param onOff
     */
    private void modifyLogSwitch(String key, boolean onOff) {
        if (logMap.containsKey(key)) {
            Boolean flag = logMap.get(key);
            flag = onOff;
        } else {
            logMap.put(key, onOff);
        }
    }

}
